# vue build stage
FROM node:lts-alpine3.19 as frontend-stage
WORKDIR /build
# RUN set -eux;
# COPY . .
# 设置代理
RUN npm config set registry https://registry.npmmirror.com/

# 安装pnpm
RUN npm install -g pnpm

# pnpm install
COPY package.json ./
RUN pnpm install


COPY .* *.config.ts *.config.js *.config.cjs ./
COPY assets ./assets
# COPY locales ./locales
COPY public ./public
# 编译
RUN pnpm build


# go build stage
FROM golang:1.22.0-alpine as backend-build
# RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN export GOPROXY=https://goproxy.io,direct
# ENV GO111MODULE=on \
    # GOPROXY=https://goproxy.cn,direct

WORKDIR /mygoapp
# go mod download
COPY go.* ./
RUN go mod download

# copy fountend dist
COPY --from=frontend-stage /build/dist ./dist

COPY internal ./internal
COPY main.go ./

RUN CGO_ENABLED=0 GOOS=linux go build -o myapp

# release
# WORKDIR /app
FROM alpine:latest
COPY --from=backend-build /mygoapp/myapp /myapp
COPY data ./data

EXPOSE 8081
# USER nonroot:nonroot
ENTRYPOINT ["/myapp"]
